'use strict';

stareal
    .controller("OthersFansListController", function ($scope, $stateParams, $api, $state,$lazyLoader,$rootScope,localStorageService,$alert) {
        $scope.authorid=$stateParams.authorid;
        $scope.comments = new $lazyLoader("app/view/fansOthers", {authorid:$scope.authorid},true)
        //用户关注
        //用户关注
        $scope.viewAttention=function(id,index) {
            if (!localStorageService.get('token')) {
                var  rs = "main.othersfans-" + JSON.stringify({authorid:$scope.authorid});
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                    // 正式地址
                    location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                        // "appid=wxd39f7e740343d507&" +
                        // "redirect_uri=http%3A%2F%2Fwww.mydeershow.com%2Foauth%2Findex" +
                        "appid=wxda73ac8ac7af1261&" +
                        "redirect_uri=http%3A%2F%2Ftest.djx.m.opentickets.cn%2Foauth%2Findex" +
                        "&response_type=code&scope=snsapi_userinfo&state="+encodeURIComponent(rs);

                    // //测试redirect_uri
                    // location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                    //     "appid=wxd39f7e740343d507&" +
                    //     "redirect_uri=http%3A%2F%2Ft.stareal.cn%2Foauth%2Findex" +
                    //     "&response_type=code&scope=snsapi_userinfo&state=" + encodeURIComponent(rs);
                } else {
                    // location.href = "https://open.weixin.qq.com/connect/qrconnect?" +
                    //     "appid=wx05c47c7db58b03aa&" +
                    //     "redirect_uri=http%3A%2F%2Fwww.stareal.cn%2Fwx%2Foauth%2Fweixin" +
                    //     "&response_type=code&scope=snsapi_login&state=" + encodeURIComponent(rs) + "#wechat_redirect";
                    location.href = "#/main/login/"+encodeURIComponent(rs);
                }
                return false;
            }
            $api.post("app/follow/create",{author_id:id},true)
                .then(function (ret) {
                    //console.log("333");
                    //  console.log(ret);
                    if(ret.follow==1){
                        //$scope.viewfavorText="已关注";
                        $scope.comments.items[index].statc=ret.statc;
                        $alert.show("关注成功!");
                        // location.reload();
                    }else{
                        //$scope.viewfavorText="+关注";
                        $scope.comments.items[index].statc=ret.statc;
                        $alert.show("取消关注!");
                       // location.reload();
                    }
                },function (err){
                    // console.log(err);
                    $alert.show(err);
                })
        }
    });